//
//  PaimingDayDetailViewController.m
//  jizhiyunduan
//
//  Created by 鞠超 on 16/4/25.
//  Copyright © 2016年 JC. All rights reserved.
//

#import "PaimingDayDetailViewController.h"

#import "PaimingMonthDetailViewController.h"

#import "PNChartDelegate.h"
#import "PNChart.h"

@interface PaimingDayDetailViewController () <UITableViewDelegate,UITableViewDataSource, UIScrollViewDelegate, PNChartDelegate>

@property (nonatomic, strong) UITableView * tableView;

//头视图
@property (nonatomic, strong) UIView * headView;
//是否是首次
@property (nonatomic, assign) NSInteger fisrt_fresh1;
@property (nonatomic, assign) NSInteger fisrt_fresh2;
@property (nonatomic, assign) NSInteger fisrt_fresh3;



@property (nonatomic) PNLineChart * lineChart1;
@property (nonatomic) PNLineChart * lineChart2;
@property (nonatomic) PNLineChart * lineChart3;

@property (nonatomic, strong) UIView * view_head;
//下拉菜单
@property (nonatomic, strong) UIView * view_pull;
@property (nonatomic, copy) NSString * str_pullType;

@property (nonatomic, strong) UIButton * btn_day;
@property (nonatomic, strong) UIButton * btn_month;
@property (nonatomic, strong) UIButton * btn_year;

//数据
@property (nonatomic, assign) NSInteger number;

@end

@implementation PaimingDayDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //状态
    self.str_pullType = @"0";
    self.fisrt_fresh1 = 0;
    self.fisrt_fresh2 = 0;
    self.fisrt_fresh3 = 0;
    self.lineChart2 = nil;
    self.lineChart3 = nil;
    
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void)p_navi
{
    _lblTitle.text = [NSString stringWithFormat:@"排名详情"];
    _lblTitle.font = [UIFont systemFontOfSize:20];
    
    [self addRightButton:@"rli@2x.png"];
    _imgRight.frame = CGRectMake(SCREEN_WIDTH - 5 - 30, _imgRight.frame.origin.y + 2, _imgRight.frame.size.width - 5, _imgRight.frame.size.height - 5);
    _btnRight.frame = CGRectMake(SCREEN_WIDTH - 10 - 40, _lblRight.frame.origin.y + 0, 40, _lblRight.frame.size.height - 10);
    
    [self addLeftButton:@"fanhui@2x.png"];
}

//左返回
- (void)clickLeftButton:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)clickRightButton:(UIButton *)sender
{
    if(self.view_pull.frame.size.height == 0)
    {
        self.view_pull = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 80, 64, 80, 0)];
        self.view_pull.backgroundColor = [UIColor whiteColor];
        //1
        self.btn_day = [UIButton buttonWithType:(UIButtonTypeSystem)];
        self.btn_day.frame = CGRectMake(0, 0, 80, 40);
        [self.btn_day setTitle:@"日排名" forState:(UIControlStateNormal)];
        self.btn_day.titleLabel.font = [UIFont systemFontOfSize:15];
        [self.btn_day setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        [self.view_pull addSubview:self.btn_day];
        [self.btn_day addTarget:self action:@selector(btn_dayAction:) forControlEvents:(UIControlEventTouchUpInside)];
        
        //2
        self.btn_month = [UIButton buttonWithType:(UIButtonTypeSystem)];
        self.btn_month.frame = CGRectMake(0, 40, 80, 40);
        [self.btn_month setTitle:@"月排名" forState:(UIControlStateNormal)];
        self.btn_month.titleLabel.font = [UIFont systemFontOfSize:15];
        [self.btn_month setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        [self.view_pull addSubview:self.btn_month];
        [self.btn_month addTarget:self action:@selector(btn_monthAction:) forControlEvents:(UIControlEventTouchUpInside)];
        
        //3
        self.btn_year = [UIButton buttonWithType:(UIButtonTypeSystem)];
        self.btn_year.frame = CGRectMake(0, 80, 80, 40);
        [self.btn_year setTitle:@"年排名" forState:(UIControlStateNormal)];
        self.btn_year.titleLabel.font = [UIFont systemFontOfSize:15];
        [self.btn_year setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        [self.view_pull addSubview:self.btn_year];
        [self.btn_year addTarget:self action:@selector(btn_yearAction:) forControlEvents:(UIControlEventTouchUpInside)];
        
        //保留痕迹
        switch ([self.str_pullType integerValue])
        {
            case 0:
            {
                [self.btn_day setTitleColor:navi_bar_bg_color forState:(UIControlStateNormal)];
            }
                break;
            case 1:
            {
                [self.btn_month setTitleColor:navi_bar_bg_color forState:(UIControlStateNormal)];
            }
                break;
            case 2:
            {
                [self.btn_year setTitleColor:navi_bar_bg_color forState:(UIControlStateNormal)];
            }
                break;
            default:
                break;
        }
        
        [UIView animateWithDuration:0.1 animations:^{
            
            self.view_pull.frame = CGRectMake(SCREEN_WIDTH - 80, 64, 80, 120);
            
        } completion:^(BOOL finished) {
            
        }];
        
        [self.view addSubview:self.view_pull];
        //        [self.view bringSubviewToFront:self.view_pull];
    }
    else
    {
        [UIView animateWithDuration:0.1 animations:^{
            
            self.view_pull.frame = CGRectMake(SCREEN_WIDTH - 80, 64, 80, 0);
            
        } completion:^(BOOL finished) {
            
            self.view_pull.hidden = YES;
            
        }];
        
    }
}

//隐藏tabbar
-(void)viewWillAppear:(BOOL)animated
{
    //处于隐藏状态
    self.view_pull.hidden = YES;
    
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void)p_setupView
{
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    
    [self p_headView];
    self.tableView.tableHeaderView = self.headView;
    self.tableView.tableFooterView = [[UIView alloc] init];
    [self.view addSubview:self.tableView];
    
    
    //
    __unsafe_unretained UITableView *tableView = self.tableView;
    __unsafe_unretained __typeof(self) weakSelf = self;
    
    // 下拉刷新
    tableView.mj_header= [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        [weakSelf p_data];
        
        // 结束刷新
        [tableView.mj_header endRefreshing];
    }];
    
    // 马上进入刷新状态
    [tableView.mj_header beginRefreshing];
    
    // 设置自动切换透明度(在导航栏下面自动隐藏)
    tableView.mj_header.automaticallyChangeAlpha = YES;
    
//    // 上拉加载
//    tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
//
//        [weakSelf p_data1];
//        // 结束刷新
//        [tableView.mj_footer endRefreshing];
//    }];
}

#pragma mark - 数据
- (void )p_data
{
    self.number = 30;
    
    switch ([self.str_pullType integerValue])
    {
        case 0:
        {
            if(self.fisrt_fresh1 == 0)
            {
                self.fisrt_fresh1 = 1;
            }
            else
            {
                self.lineChart1.displayAnimated = YES;
                [self.lineChart1 strokeChart];
            }
        }
            break;
        case 1:
        {
            if(self.fisrt_fresh2 == 0)
            {
                self.fisrt_fresh2 = 1;
            }
            else
            {
                self.lineChart2.displayAnimated = YES;
                [self.lineChart2 strokeChart];
            }
        }
            break;
        case 2:
        {
            if(self.fisrt_fresh3 == 0)
            {
                self.fisrt_fresh3 = 1;
            }
            else
            {
                self.lineChart3.displayAnimated = YES;
                [self.lineChart3 strokeChart];
            }
        }
            break;
        default:
            break;
    }

    dispatch_async(dispatch_get_main_queue(), ^{
        //刷新tableView(记住,要更新放在主线程中)
        [self.tableView reloadData];
    });
}

#pragma mark - 头视图
- (void )p_headView
{
    self.headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 300)];
    self.headView.backgroundColor = [UIColor whiteColor];
    
    
    self.lineChart1 = [[PNLineChart alloc] initWithFrame:CGRectMake(10, 15, SCREEN_WIDTH - 20, 270)];
    self.lineChart1.yLabelFormat = @"%d";
    self.lineChart1.backgroundColor = [UIColor clearColor];
    [self.headView addSubview:self.lineChart1];
    
    //7天数据 x轴
    [self.lineChart1 setXLabels:@[@"12.1",@"12.2",@"12.3",@"12.4",@"12.5",@"12.6",@"12.7"]];
    //是否显示 x轴
    self.lineChart1.showCoordinateAxis = YES;
    
    self.lineChart1.yFixedValueMax = 1;
    self.lineChart1.yFixedValueMin = 100;
    
    self.lineChart1.yLabelFont = [UIFont systemFontOfSize:10];
    [self.lineChart1 setYLabels:@[
                                  @"100",
                                  @"90",
                                  @"80",
                                  @"70",
                                  @"60",
                                  @"50",
                                  @"40",
                                  @"30",
                                  @"20",
                                  @"10",
                                  @"1",
                                  ]
     ];
    
    //线
    NSArray * data01Array = @[@33, @76, @26, @47, @16, @32, @16];
    PNLineChartData *data01 = [PNLineChartData new];
    data01.dataTitle = @"7日内排名";
    data01.color = [UIColor orangeColor];
    data01.alpha = 0.3f;
    data01.itemCount = data01Array.count;
    data01.inflexionPointStyle = PNLineChartPointStyleTriangle;
    data01.getData = ^(NSUInteger index) {
        CGFloat yValue = [data01Array[index] floatValue];
        return [PNLineChartDataItem dataItemWithY:yValue];
    };
    
    self.lineChart1.chartData = @[data01];
    [self.lineChart1 strokeChart];
    self.lineChart1.delegate = self;
    
    
    self.lineChart1.legendStyle = PNLegendItemStyleStacked;
    self.lineChart1.legendFont = [UIFont boldSystemFontOfSize:12.0f];
    self.lineChart1.legendFontColor = [UIColor orangeColor];
    
    UIView *legend = [self.lineChart1 getLegendWithMaxWidth:200];
    [legend setFrame:CGRectMake(50, 10, 200, 30)];
    [self.lineChart1 addSubview:legend];

}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.number;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [[UITableViewCell alloc] init];
    cell.backgroundColor = [UIColor whiteColor];
    
    switch ([self.str_pullType integerValue])
    {
        case 0:
        {
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            CGFloat list_x = (SCREEN_WIDTH - 10) / 4;
            
            //需要空2格
            UILabel * lbl_1 = [[UILabel alloc] initWithFrame:CGRectMake(5 , 7.5, list_x * 2, 30)];
            lbl_1.text = [NSString stringWithFormat:@"  网站关键词"];
            lbl_1.textColor = [UIColor blackColor];
            lbl_1.font = [UIFont systemFontOfSize:13];
            [cell addSubview:lbl_1];
            
            UILabel * lbl_2 = [[UILabel alloc] initWithFrame:CGRectMake(5 + list_x * 2, 7.5, list_x * 1, 30)];
            lbl_2.text = [NSString stringWithFormat:@"%d",indexPath.row + 11];
            lbl_2.textColor = [UIColor blackColor];
            lbl_2.textAlignment = NSTextAlignmentCenter;
            lbl_2.font = [UIFont systemFontOfSize:15];
            [cell addSubview:lbl_2];
            
            UILabel * lbl_3 = [[UILabel alloc] initWithFrame:CGRectMake(5 + list_x * 3, 7.5, list_x * 1, 30)];
            lbl_3.text = [NSString stringWithFormat:@"12-%d",indexPath.row + 1];
            lbl_3.textColor = [UIColor blackColor];
            lbl_3.textAlignment = NSTextAlignmentCenter;
            lbl_3.font = [UIFont systemFontOfSize:15];
            [cell addSubview:lbl_3];
        }
            break;
        case 1:
        {
            CGFloat list_x = (SCREEN_WIDTH - 30) / 4;
            
            //需要空3格
            UILabel * lbl_1 = [[UILabel alloc] initWithFrame:CGRectMake(5 , 7.5, list_x * 2, 30)];
            lbl_1.text = [NSString stringWithFormat:@"  关键字网站"];
            lbl_1.textColor = [UIColor blackColor];
            lbl_1.font = [UIFont systemFontOfSize:13];
            [cell addSubview:lbl_1];
            
            UILabel * lbl_2 = [[UILabel alloc] initWithFrame:CGRectMake(5 + list_x * 2, 7.5, list_x * 1, 30)];
            lbl_2.text = [NSString stringWithFormat:@"%d",31 - indexPath.row];
            lbl_2.textColor = [UIColor blackColor];
            lbl_2.textAlignment = NSTextAlignmentCenter;
            lbl_2.font = [UIFont systemFontOfSize:15];
            [cell addSubview:lbl_2];
            
            UILabel * lbl_3 = [[UILabel alloc] initWithFrame:CGRectMake(5 + list_x * 3, 7.5, list_x * 1, 30)];
            lbl_3.text = [NSString stringWithFormat:@"%d月份",indexPath.row + 1];
            lbl_3.textColor = [UIColor blackColor];
            lbl_3.textAlignment = NSTextAlignmentCenter;
            lbl_3.font = [UIFont systemFontOfSize:15];
            [cell addSubview:lbl_3];
            
            UIImageView * image = [[UIImageView alloc] initWithFrame:CGRectMake(5 + list_x * 4 + 2.5, 12.5, 20, 20)];
            image.image = [UIImage imageNamed:@"youfanhui.png"];
            [cell addSubview:image];
        }
            break;
        case 2:
        {
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            CGFloat list_x = (SCREEN_WIDTH - 10) / 4;
            //需要空3格
            UILabel * lbl_1 = [[UILabel alloc] initWithFrame:CGRectMake(5 , 7.5, list_x * 2, 30)];
            lbl_1.text = [NSString stringWithFormat:@"  关键字"];
            lbl_1.textColor = [UIColor blackColor];
            lbl_1.font = [UIFont systemFontOfSize:13];
            [cell addSubview:lbl_1];
            
            UILabel * lbl_2 = [[UILabel alloc] initWithFrame:CGRectMake(5 + list_x * 2, 7.5, list_x, 30)];
            lbl_2.text = [NSString stringWithFormat:@"%d",(indexPath.row + 1) * 2];
            lbl_2.textColor = [UIColor blackColor];
            lbl_2.textAlignment = NSTextAlignmentCenter;
            lbl_2.font = [UIFont systemFontOfSize:15];
            [cell addSubview:lbl_2];
            
            UILabel * lbl_3 = [[UILabel alloc] initWithFrame:CGRectMake(5 + list_x * 3, 7.5, list_x, 30)];
            lbl_3.text = [NSString stringWithFormat:@"20%d年度",indexPath.row + 10];
            lbl_3.textColor = [UIColor blackColor];
            lbl_3.textAlignment = NSTextAlignmentCenter;
            lbl_3.font = [UIFont systemFontOfSize:15];
            [cell addSubview:lbl_3];
        }
            break;
            
        default:
            break;
    }
    
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    self.view_head = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 35)];
    self.view_head.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    switch ([self.str_pullType integerValue])
    {
        case 0:
        {
            CGFloat list_x = (SCREEN_WIDTH - 10) / 4;
            
            //1
            UILabel * list_1 = [[UILabel alloc] initWithFrame:CGRectMake(5 , 7.5, list_x * 2, 20)];
            list_1.text = @"  关键词";
            list_1.textColor = navi_bar_bg_color;
            list_1.font = [UIFont systemFontOfSize:13];
            //    list_1.textAlignment = NSTextAlignmentCenter;
            [self.view_head addSubview:list_1];
            
            //2
            UILabel * list_2 = [[UILabel alloc] initWithFrame:CGRectMake(5 + list_x * 2, 7.5, list_x * 1, 20)];
            list_2.text = @"排名";
            list_2.textColor = navi_bar_bg_color;
            list_2.font = [UIFont systemFontOfSize:13];
            list_2.textAlignment = NSTextAlignmentCenter;
            [self.view_head addSubview:list_2];
            
            //3
            UILabel * list_3 = [[UILabel alloc] initWithFrame:CGRectMake(5 + list_x * 3, 7.5, list_x * 1, 20)];
            list_3.text = @"日期";
            list_3.textColor = navi_bar_bg_color;
            list_3.font = [UIFont systemFontOfSize:13];
            list_3.textAlignment = NSTextAlignmentCenter;
            [self.view_head addSubview:list_3];
        }
            break;
        case 1:
        {
            CGFloat list_x = (SCREEN_WIDTH - 30) / 4;
            
            //1
            UILabel * list_1 = [[UILabel alloc] initWithFrame:CGRectMake(5 , 7.5, list_x * 2, 20)];
            list_1.text = @"  关键词";
            list_1.textColor = navi_bar_bg_color;
            list_1.font = [UIFont systemFontOfSize:13];
            //    list_1.textAlignment = NSTextAlignmentCenter;
            [self.view_head addSubview:list_1];
            
            //2
            UILabel * list_2 = [[UILabel alloc] initWithFrame:CGRectMake(5 + list_x * 2, 7.5, list_x * 1, 20)];
            list_2.text = @"排名";
            list_2.textColor = navi_bar_bg_color;
            list_2.font = [UIFont systemFontOfSize:13];
            list_2.textAlignment = NSTextAlignmentCenter;
            [self.view_head addSubview:list_2];
            
            //3
            UILabel * list_3 = [[UILabel alloc] initWithFrame:CGRectMake(5 + list_x * 3, 7.5, list_x * 1, 20)];
            list_3.text = @"月份";
            list_3.textColor = navi_bar_bg_color;
            list_3.font = [UIFont systemFontOfSize:13];
            list_3.textAlignment = NSTextAlignmentCenter;
            [self.view_head addSubview:list_3];
        }
            break;
        case 2:
        {
            CGFloat list_x = (SCREEN_WIDTH - 10) / 4;
            
            //1
            UILabel * list_1 = [[UILabel alloc] initWithFrame:CGRectMake(5 , 7.5, list_x * 2, 20)];
            list_1.text = @"  关键词";
            list_1.textColor = navi_bar_bg_color;
            list_1.font = [UIFont systemFontOfSize:13];
            //    list_1.textAlignment = NSTextAlignmentCenter;
            [self.view_head addSubview:list_1];
            
            //2
            UILabel * list_2 = [[UILabel alloc] initWithFrame:CGRectMake(5 + list_x * 2, 7.5, list_x * 1, 20)];
            list_2.text = @"排名";
            list_2.textColor = navi_bar_bg_color;
            list_2.font = [UIFont systemFontOfSize:13];
            list_2.textAlignment = NSTextAlignmentCenter;
            [self.view_head addSubview:list_2];
            
            //3
            UILabel * list_3 = [[UILabel alloc] initWithFrame:CGRectMake(5 + list_x * 3, 7.5, list_x * 1, 20)];
            list_3.text = @"年排名";
            list_3.textColor = navi_bar_bg_color;
            list_3.font = [UIFont systemFontOfSize:13];
            list_3.textAlignment = NSTextAlignmentCenter;
            [self.view_head addSubview:list_3];
            
        }
            break;
        default:
            break;
    }
    
    return self.view_head;
}

- (CGFloat )tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 35.0f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if([self.str_pullType isEqualToString:@"1"])
    {
        PaimingMonthDetailViewController * paimingMonthDetailViewController = [[PaimingMonthDetailViewController alloc] init];
        
        [self showViewController:paimingMonthDetailViewController sender:nil];
    }
}

#pragma mark - scrollView代理
- (void )scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [UIView animateWithDuration:0.1 animations:^{
        
        self.view_pull.frame = CGRectMake(SCREEN_WIDTH - 80, 64, 80, 0);
        
    } completion:^(BOOL finished) {
        
        self.view_pull.hidden = YES;
        
    }];
}

- (void )touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [UIView animateWithDuration:0.1 animations:^{
        
        self.view_pull.frame = CGRectMake(SCREEN_WIDTH - 80, 64, 80, 0);
        
    } completion:^(BOOL finished) {
        
        self.view_pull.hidden = YES;
        
    }];
}


#pragma mark - 右侧点击事件
//日
- (void)btn_dayAction:(UIButton *)sender
{
    self.fisrt_fresh1 = 0;
    self.str_pullType = @"0";
    
    [UIView animateWithDuration:0.1 animations:^{
        
        self.view_pull.frame = CGRectMake(SCREEN_WIDTH - 80, 64, 80, 0);
        
    } completion:^(BOOL finished) {
        
        self.view_pull.hidden = YES;
        
    }];
    
    [self.btn_day setTitleColor:navi_bar_bg_color forState:(UIControlStateNormal)];
    
    
    [self.btn_month setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [self.btn_year setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    
    
    //1
    self.lineChart2.hidden = YES;
    self.lineChart3.hidden = YES;
    
    if(self.lineChart1.hidden == YES)
    {
        self.lineChart1 = [[PNLineChart alloc] initWithFrame:CGRectMake(10, 15, SCREEN_WIDTH - 20, 270)];
        self.lineChart1.yLabelFormat = @"%d";
        self.lineChart1.backgroundColor = [UIColor clearColor];
        [self.headView addSubview:self.lineChart1];
        
        //7天数据 x轴
        [self.lineChart1 setXLabels:@[@"12.1",@"12.2",@"12.3",@"12.4",@"12.5",@"12.6",@"12.7"]];
        //是否显示 x轴
        self.lineChart1.showCoordinateAxis = YES;
        
        self.lineChart1.yFixedValueMax = 1;
        self.lineChart1.yFixedValueMin = 100;
        
        self.lineChart1.yLabelFont = [UIFont systemFontOfSize:10];
        [self.lineChart1 setYLabels:@[
                                      @"100",
                                      @"90",
                                      @"80",
                                      @"70",
                                      @"60",
                                      @"50",
                                      @"40",
                                      @"30",
                                      @"20",
                                      @"10",
                                      @"1",
                                      ]
         ];
        
        //线
        NSArray * data01Array = @[@33, @76, @26, @47, @16, @32, @16];
        PNLineChartData *data01 = [PNLineChartData new];
        data01.dataTitle = @"7日内排名";
        data01.color = [UIColor orangeColor];
        data01.alpha = 0.3f;
        data01.itemCount = data01Array.count;
        data01.inflexionPointStyle = PNLineChartPointStyleTriangle;
        data01.getData = ^(NSUInteger index) {
            CGFloat yValue = [data01Array[index] floatValue];
            return [PNLineChartDataItem dataItemWithY:yValue];
        };
        
        self.lineChart1.chartData = @[data01];
        [self.lineChart1 strokeChart];
        self.lineChart1.delegate = self;
        
        
        self.lineChart1.legendStyle = PNLegendItemStyleStacked;
        self.lineChart1.legendFont = [UIFont boldSystemFontOfSize:12.0f];
        self.lineChart1.legendFontColor = [UIColor orangeColor];
        
        UIView *legend = [self.lineChart1 getLegendWithMaxWidth:200];
        [legend setFrame:CGRectMake(50, 10, 200, 30)];
        [self.lineChart1 addSubview:legend];
    }
    
    // 马上进入刷新状态
    [self.tableView.mj_header beginRefreshing];
}

//月
- (void)btn_monthAction:(UIButton *)sender
{
    self.fisrt_fresh2 = 0;
    self.str_pullType = @"1";
    
    [UIView animateWithDuration:0.1 animations:^{
        
        self.view_pull.frame = CGRectMake(SCREEN_WIDTH - 80, 64, 80, 0);
        
    } completion:^(BOOL finished) {
        
        self.view_pull.hidden = YES;
        
    }];
    
    [self.btn_month setTitleColor:navi_bar_bg_color forState:(UIControlStateNormal)];
    
    [self.btn_day setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [self.btn_year setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    
    
    
    //2
    self.lineChart1.hidden = YES;
    self.lineChart3.hidden = YES;
    
    if(self.lineChart2.hidden == YES || self.lineChart2 == nil)
    {
        self.lineChart2 = [[PNLineChart alloc] initWithFrame:CGRectMake(5, 15, SCREEN_WIDTH , 270)];
        self.lineChart2.yLabelFormat = @"%d";
        self.lineChart2.backgroundColor = [UIColor clearColor];
        [self.headView addSubview:self.lineChart2];
        
        //7天数据 x轴
        [self.lineChart2 setXLabels:@[@"1月",@"2月",@"3月",@"4月",@"5月",@"6月",@"7月",@"8月",@"9月",@"10月",@"11月",@"12月"]];
        //是否显示 x轴
        self.lineChart2.showCoordinateAxis = YES;
        
        self.lineChart2.yFixedValueMax = 1;
        self.lineChart2.yFixedValueMin = 100;
        
        self.lineChart2.yLabelFont = [UIFont systemFontOfSize:9];
        [self.lineChart2 setYLabels:@[
                                      @"100",
                                      @"90",
                                      @"80",
                                      @"70",
                                      @"60",
                                      @"50",
                                      @"40",
                                      @"30",
                                      @"20",
                                      @"10",
                                      @"1",
                                      ]
         ];
        
        //线
        NSArray * data01Array = @[@33, @10, @76, @57, @66, @10, @46, @33, @60, @26, @70, @60];
        PNLineChartData *data01 = [PNLineChartData new];
        data01.dataTitle = @"月排名";
        data01.color = [UIColor brownColor];
        data01.alpha = 0.3f;
        data01.itemCount = data01Array.count;
        data01.inflexionPointStyle = PNLineChartPointStyleTriangle;
        data01.getData = ^(NSUInteger index) {
            CGFloat yValue = [data01Array[index] floatValue];
            return [PNLineChartDataItem dataItemWithY:yValue];
        };
        
        self.lineChart2.chartData = @[data01];
        [self.lineChart2 strokeChart];
        self.lineChart2.delegate = self;
        
        
        self.lineChart2.legendStyle = PNLegendItemStyleStacked;
        self.lineChart2.legendFont = [UIFont boldSystemFontOfSize:12.0f];
        self.lineChart2.legendFontColor = [UIColor brownColor];
        
        UIView *legend = [self.lineChart2 getLegendWithMaxWidth:200];
        [legend setFrame:CGRectMake(50, 10, 200, 30)];
        [self.lineChart2 addSubview:legend];
    }

    
    // 马上进入刷新状态
    [self.tableView.mj_header beginRefreshing];
}

//年
- (void)btn_yearAction:(UIButton *)sender
{
    self.fisrt_fresh3 = 0;
    
    self.str_pullType = @"2";
    
    [UIView animateWithDuration:0.1 animations:^{
        
        self.view_pull.frame = CGRectMake(SCREEN_WIDTH - 80, 64, 80, 0);
        
    } completion:^(BOOL finished) {
        
        self.view_pull.hidden = YES;
        
    }];
    
    [self.btn_year setTitleColor:navi_bar_bg_color forState:(UIControlStateNormal)];
    
    [self.btn_day setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [self.btn_month setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    
    //3
    self.lineChart1.hidden = YES;
    self.lineChart2.hidden = YES;
    
    if(self.lineChart3.hidden == YES || self.lineChart3 == nil)
    {
        self.lineChart3 = [[PNLineChart alloc] initWithFrame:CGRectMake(5, 15, SCREEN_WIDTH , 270)];
        self.lineChart3.yLabelFormat = @"%d";
        self.lineChart3.backgroundColor = [UIColor clearColor];
        [self.headView addSubview:self.lineChart3];
        
        //7天数据 x轴
        [self.lineChart3 setXLabels:@[@"2015.1",@"5月",@"9月",@"12月",@"2016.1",@"5月",@"9月",@"12月"]];
        //是否显示 x轴
        self.lineChart3.showCoordinateAxis = YES;
        
        self.lineChart3.yFixedValueMax = 1;
        self.lineChart3.yFixedValueMin = 100;
        
        self.lineChart3.yLabelFont = [UIFont systemFontOfSize:9];
        [self.lineChart3 setYLabels:@[
                                      @"100",
                                      @"90",
                                      @"80",
                                      @"70",
                                      @"60",
                                      @"50",
                                      @"40",
                                      @"30",
                                      @"20",
                                      @"10",
                                      @"1",
                                      ]
         ];
        
        //线
        NSArray * data01Array = @[@33, @10, @76, @57, @66, @10, @46, @33];
        PNLineChartData *data01 = [PNLineChartData new];
        data01.dataTitle = @"季度排名";
        data01.color = [UIColor redColor];
        data01.alpha = 0.3f;
        data01.itemCount = data01Array.count;
        data01.inflexionPointStyle = PNLineChartPointStyleTriangle;
        data01.getData = ^(NSUInteger index) {
            CGFloat yValue = [data01Array[index] floatValue];
            return [PNLineChartDataItem dataItemWithY:yValue];
        };
        
        self.lineChart3.chartData = @[data01];
        [self.lineChart3 strokeChart];
        self.lineChart3.delegate = self;
        
        
        self.lineChart3.legendStyle = PNLegendItemStyleStacked;
        self.lineChart3.legendFont = [UIFont boldSystemFontOfSize:12.0f];
        self.lineChart3.legendFontColor = [UIColor redColor];
        
        UIView *legend = [self.lineChart3 getLegendWithMaxWidth:200];
        [legend setFrame:CGRectMake(50, 10, 200, 30)];
        [self.lineChart3 addSubview:legend];
    }
    
    // 马上进入刷新状态
    [self.tableView.mj_header beginRefreshing];
}

#pragma mark - 点击方法
- (void)userClickedOnLineKeyPoint:(CGPoint)point lineIndex:(NSInteger)lineIndex pointIndex:(NSInteger)pointIndex
{
    
}

- (void)userClickedOnLinePoint:(CGPoint)point lineIndex:(NSInteger)lineIndex
{
    
}



@end
